using System;
using System.Runtime.Serialization;
using System.Security.Permissions;

namespace Kenly.DBFramework.Gateway
{
	/// <summary>
    /// Represents the exception that raises when executing a command.
	/// </summary>
    [Serializable]
    public class GatewayException : Exception
    {
        private object _customSource;
        private string _message;

        /// <summary>
        /// 
        /// </summary>
        public object CustomSource
        {
            get
            {
                return _customSource;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Text
        {
            get
            {
                return _message;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public GatewayException()
            : base()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public GatewayException(string message)
            : base(message)
        {
            _message = message;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="customSource"></param>
        public GatewayException(string message, object customSource)
            : base(message)
        {
            _customSource = customSource;
            _message = message;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="customSource"></param>
        /// <param name="ex"></param>
        public GatewayException(string message, object customSource, Exception ex)
            : base(message,ex)
        {
            _customSource = customSource;
            _message = message;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public GatewayException(string message, Exception ex)
            : base(message, ex)
        {
            _message = message;
        }

        //protected GatewayException(SerializationInfo info, StreamingContext context)
        //    : base(info, context)
        //{
        //    if (info == null)
        //    {
        //        throw new ArgumentNullException("info");
        //    }
        //    _message = info.GetString("Text");
        //}

        //protected virtual void GetObjectData(SerializationInfo info, StreamingContext context) 
        //{
        //    info.AddValue("Text", _message); 
        //}

        //[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        //void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) 
        //{
        //    if (info == null)
        //    {
        //        throw new ArgumentNullException("info");
        //    }
        //    GetObjectData(info, context); 
        //}

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.Message;
        }

    }

}
